<template>
  <basic-dialog
    :width="'40%'"
    :visible.sync="reviewVisible"
    :title="'复合意见填写'"
    :handle-close="handleCloseDialog"
    :handle-ok="handleConfirm"
    :loadingBtn="confirmLoading"
    :okText="'提交'"
  >
    <el-form
      ref="formData"
      :model="formData"
      :rules="formValidate"
      label-width="100px"
    >
      <el-form-item label="解决措施是否合理" prop="isSolutionReasonable">
        <el-select
          v-model.trim="formData.isSolutionReasonable"
          placeholder="请选择解决措施是否合理"
          @change="handleSolutionChange"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否推送经理" prop="isPushManage">
        <el-select
          :disabled="formData.isSolutionReasonable == 1"
          v-model.trim="formData.isPushManage"
          placeholder="请选择是否推送经理"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="复核意见" prop="reviewOpinion">
        <el-input
          type="textarea"
          v-model.trim="formData.reviewOpinion"
          placeholder="请输入复核意见"
          show-word-limit
          maxlength="300"
          rows="4"
        />
      </el-form-item>
    </el-form>
  </basic-dialog>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
import { reviewService } from '@api/stock/stockOverflow';
export default {
  components: {
    BasicDialog
  },
  props: {
    reviewVisible: {
      type: Boolean,
      default: false
    },
    selectIds: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      confirmLoading: false,
      formData: {
        isSolutionReasonable: '',
        isPushManage: '',
        reviewOpinion: '',
      },
      formValidate: {
        isSolutionReasonable: [
          { required: true, message: '请选择解决措施是否合理', trigger: 'change' }
        ],
      },
      options: [
        { value: '1', label: '是' },
        { value: '0', label: '否' },
      ],
    };
  },
  methods: {
    handleSolutionChange (val) {
      if (val == 1) {
        this.formData.isPushManage = '0'
      } else {
        this.formData.isPushManage = ''
      }
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$refs.formData.resetFields();
      this.$emit('update:reviewVisible', false);
    },
    handleConfirm () {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          const param = {
            idList: this.selectIds,
            ...this.formData
          };
          this.setCauseReasons(param)
        }
      });
    },
    async setCauseReasons (param) {
      const res = await reviewService(
        param,
        state => { this.confirmLoading = state }
      );
      if (res) {
        this.$message.success('操作成功')
        this.$emit('getTableData');
        this.handleCloseDialog();
      }
    },
  }
};
</script>
<style scoped>
.el-select, .el-date-editor.el-input {
  width: 100%;
}
</style>
